With string.StartsWith(char)
and string.EndsWith(char)
, only the first character of the string is compared to the
provided character, whereas the string
versions of those methods have to do checks about the current StringComparison
and
CultureInfo
. Thus, the char
overloads are significantly faster for default comparison scenarios.
These overloads were introduced in .NET Core 2.0
.
What is the potential impact?
We measured at least 3.5x improvement in execution time. For more details see the Benchmarks
section from the More info
tab.